//
//  Node.cpp
//  RoutingEvaluator
//
//  Created by Christopher Kemsley on 4/15/12.
//  Copyright (c) 2012 iAppolopolis. All rights reserved.
//

#import "Node.hpp"

NamespaceBegin





Node*	Node :: createNode	( NodeInfo * identity )
	{
	return new Node ( identity ) ;
	}



std::vector<Link*> const&	Node :: links ()
	{
	return mLinks ;
	}


Node :: Node ( NodeInfo * inIdentity )
:	Object()
,	identity(inIdentity)
,	mLinks()
	{
	
	}



NodeSet*		NodeSet :: createSetWithNodes	( NodeInfoSet * set )
	{
	return new NodeSet ( set ) ;
	}


Node*	NodeSet :: nodeWithNodeInfo		( NodeInfo * info )
	{
	std::vector<Node*>::iterator	here	=	mNodes.begin() ;
	std::vector<Node*>::iterator	end		=	mNodes.end() ;
	while ( here < end )
		{
		Node * n = *(here++) ;
		if ( n->identity == info )
			return n ;
		}
	return 0 ;
	}
Node*	NodeSet :: nodeWithIdentifier	( Identifier const & identifier )
	{
	std::vector<Node*>::iterator	here	=	mNodes.begin() ;
	std::vector<Node*>::iterator	end		=	mNodes.end() ;
	while ( here < end )
		{
		Node * n = *(here++) ;
		if ( (n->identity->identifier) == identifier )
			return n ;
		}
	return 0 ;
	}


std::vector<Node*> const&	NodeSet :: nodes ()
	{
	return mNodes ;
	}


NodeSet :: NodeSet ( NodeInfoSet * set )
:	mNodes ()
	{
	mNodes . reserve ( set->nodes().size() ) ;
	
	std::vector<NodeInfo*>::const_iterator	here	=	set->nodes().begin() ;
	std::vector<NodeInfo*>::const_iterator	end		=	set->nodes().end() ;
	while ( here < end )
		{
		NodeInfo * info = *(here++) ;
		Node * n = Node :: createNode ( info ) ;
		mNodes . push_back ( n ) ;
		}
	}



NamespaceEnd
